/*
 * Copyright 2011 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fr.gaellalire.jzip.test.macosx;

import org.rococoa.ID;
import org.rococoa.Rococoa;
import org.rococoa.cocoa.foundation.NSNotification;
import org.rococoa.cocoa.foundation.NSObject;
import org.rococoa.cocoa.foundation.NSPoint;

import fr.gaellalire.jzip.macosx.cocoa.NSPasteboard;

public class WindowDelegateHook implements NSWindow.Delegate {

    private NSObject proxy;

    private ID id;

    protected NSObject proxy(Class<? extends NSObject> type) {
        if (null == proxy) {
            proxy = Rococoa.proxy(this, type);
        }
        return proxy;
    }

    protected org.rococoa.ID id(Class<? extends NSObject> type) {
        if (null == id) {
            id = this.proxy(type).id();
        }
        return id;
    }

    public org.rococoa.ID id() {
        return this.id(NSObject.class);
    }

    private NSWindow.Delegate delegate;

    public WindowDelegateHook(NSWindow.Delegate delegate) {
        this.delegate = delegate;
    }

    @Override
    public boolean windowShouldClose(NSWindow sender) {
        return delegate.windowShouldClose(sender);
    }

    @Override
    public void windowWillClose(NSNotification notification) {
        delegate.windowWillClose(notification);
    }

    @Override
    public void windowDidBecomeKey(NSNotification notification) {
        delegate.windowDidBecomeKey(notification);
    }

    @Override
    public void windowDidBecomeMain(NSNotification notification) {
        delegate.windowDidBecomeMain(notification);
    }

    @Override
    public void windowDidResignKey(NSNotification notification) {
        delegate.windowDidResignKey(notification);
    }

    @Override
    public void windowDidResignMain(NSNotification notification) {
        delegate.windowDidResignMain(notification);
    }

    public boolean window_shouldDragDocumentWithEvent_from_withPasteboard(NSWindow window, NSEvent event, NSPoint dragImageLocation, NSPasteboard pasteboard) {
        System.out.println("demande drag");
        return false;
    }

    @Override
    public void windowWillMove(NSNotification notification) {
        delegate.windowWillMove(notification);
    }

    @Override
    public void windowDidMove(NSNotification notification) {
        delegate.windowDidMove(notification);
    }

    @Override
    public void windowDidChangeScreen(NSNotification notification) {
        delegate.windowDidChangeScreen(notification);
    }

    @Override
    public void windowDidChangeScreenProfile(NSNotification notification) {
        delegate.windowDidChangeScreenProfile(notification);
    }

}
